package com.blog.cmrpersonalblog.strategy.upload.impl;

import com.blog.cmrpersonalblog.enums.FileUploadType;
import com.blog.cmrpersonalblog.strategy.upload.AbstractFileUploadStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * 头像上传策略
 */
@Slf4j
@Component
public class AvatarUploadStrategy extends AbstractFileUploadStrategy {
    
    @Override
    public FileUploadType getSupportedType() {
        return FileUploadType.AVATAR;
    }
    
    @Override
    public boolean isValidFileType(MultipartFile file) {
        // 头像只支持常见图片格式
        String extension = getFileExtension(file.getOriginalFilename());
        return SUPPORTED_IMAGE_TYPES.contains(extension.toLowerCase());
    }
    
    @Override
    public String generateFileName(String originalFileName, Long userId, Object... extraParams) {
        // 头像使用特殊的命名规则：avatar_用户ID_时间戳.扩展名
        String extension = getFileExtension(originalFileName);
        String timestamp = String.valueOf(System.currentTimeMillis());
        
        return String.format("avatar_user%d_%s.%s", userId, timestamp, extension);
    }
}
